package cn.wolfcode.wolf2w.business.listener;

import cn.wolfcode.wolf2w.business.api.domain.Strategy;
import cn.wolfcode.wolf2w.business.api.domain.StrategyES;
import cn.wolfcode.wolf2w.business.repository.StrategyEsRepository;
import cn.wolfcode.wolf2w.common.core.utils.bean.BeanUtils;
import com.alibaba.fastjson.JSON;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SearchRabbitListener {
    @Autowired
    private StrategyEsRepository strategyEsRepository;
    @RabbitListener(queues = "strategyQueue")
    public void onMessage(String msg) {
        Strategy strategy = JSON.parseObject(msg, Strategy.class);
        StrategyES strategyES = new StrategyES();
        BeanUtils.copyProperties(strategy, strategyES);
        strategyEsRepository.save(strategyES);
    }

}
